//
//  ListViewController.m
//  DA_V
//
//  Created by 中亿世联前台 on 15/5/6.
//  Copyright (c) 2015年 zhouhai. All rights reserved.
//

#import "ListViewController.h"
#import "MyListViewController.h"
#import "UserListViewController.h"
#import "AddCargoListViewController.h"
#import "NextListsController.h"
#import "InterFace.h"
#import "UIViewAdditions.h"
#import "InformationButton.h"
#import "InfoViewController.h"
#import "AutomaticViewController.h"

#import "AlertView.h"
#import "AccountViewController.h"
@interface ListViewController ()
{

    UIView  *_alertBackview;
    AlertView *_alerView;
}
@end

@implementation ListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    title.textAlignment = NSTextAlignmentCenter;
    title.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
    title.text = @"我的订单";
    title.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = title;
    
    InformationButton *infonmationBut = [[InformationButton alloc] initWithFrame:CGRectMake(0, 0, 23, 29)];
    infonmationBut.informationNum.text = @"20";
    [infonmationBut setImage:[UIImage imageNamed:@"查看库存_03"] forState:UIControlStateNormal];
    UIBarButtonItem *rightBut = [[UIBarButtonItem alloc] initWithCustomView:infonmationBut];
    [infonmationBut addTarget:self action:@selector(informationClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = rightBut;
    
    [self createListView];
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden= NO;
}
#pragma -mark 创建订单View按钮

- (void)createListView{
    
    //库存订单
    UIButton *kuCunList = [[UIButton alloc] initWithFrame:CGRectMake(20, 94, (SCREEN_WIDTH-70)/3.0, (SCREEN_WIDTH-70)/3.0)];
    kuCunList.layer.borderWidth = 1.0;
    kuCunList.layer.borderColor = BackColor.CGColor;
    kuCunList.layer.cornerRadius = 10/2;
    kuCunList.backgroundColor = LineColor;
    [kuCunList addTarget:self action:@selector(kuCunListBut:) forControlEvents:UIControlEventTouchUpInside];
   
    [self.view addSubview:kuCunList];
    
    UIImageView *kucunImage = [[UIImageView alloc] initWithFrame:CGRectMake((kuCunList.frame.size.width - 40)/2, 10, 40, 40)];
    kucunImage.image = [UIImage imageNamed:@"dingdan_03"];
    [kuCunList addSubview:kucunImage];
    
    UILabel *kucunTitle = [[UILabel alloc] initWithFrame:CGRectMake(kucunImage.frame.origin.x-10, kucunImage.bottom, kuCunList.frame.size.width-20, 30)];
    kucunTitle.text = @"库存订单";
    kucunTitle.textColor = DaoHangColor;
    kucunTitle.font = [UIFont fontWithName:nil size:15];
    [kuCunList addSubview:kucunTitle];
    
    //客户订单
    UIButton *userList = [[UIButton alloc] initWithFrame:CGRectMake(kuCunList.right+15, 94, (SCREEN_WIDTH-70)/3.0, (SCREEN_WIDTH-70)/3.0)];
    userList.layer.borderWidth = 1.0;
    userList.layer.borderColor = BackColor.CGColor;
    userList.layer.cornerRadius = 10/2;
    userList.backgroundColor = LineColor;
    [userList addTarget:self action:@selector(keFuListBut:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:userList];
    
    
    UIImageView *userlistImage = [[UIImageView alloc] initWithFrame:CGRectMake((kuCunList.frame.size.width - 40)/2, 10, 40, 40)];
    userlistImage.image = [UIImage imageNamed:@"dingdan_05"];
    [userList addSubview:userlistImage];
    
    UILabel *userTitle = [[UILabel alloc] initWithFrame:CGRectMake(kucunImage.frame.origin.x-10, kucunImage.bottom, kuCunList.frame.size.width-20, 30)];
    userTitle.text = @"客户订单";
    userTitle.textColor = DaoHangColor;
    userTitle.font = [UIFont fontWithName:nil size:15];
    [userList addSubview:userTitle];

    
    //下线订单
    UIButton *nextList = [[UIButton alloc] initWithFrame:CGRectMake(userList.right+15, 94, (SCREEN_WIDTH-70)/3.0, (SCREEN_WIDTH-70)/3.0)];
    nextList.layer.borderWidth = 1.0;
    nextList.layer.borderColor = BackColor.CGColor;
    nextList.layer.cornerRadius = 10/2;
    nextList.backgroundColor = LineColor;
    [nextList addTarget:self action:@selector(nextListClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:nextList];
    
    
    UIImageView *nextImage = [[UIImageView alloc] initWithFrame:CGRectMake((kuCunList.frame.size.width - 40)/2, 10, 40, 40)];
    nextImage.image = [UIImage imageNamed:@"dingdan_07"];
    [nextList addSubview:nextImage];
    UILabel *nextTitle = [[UILabel alloc] initWithFrame:CGRectMake(kucunImage.frame.origin.x-10, kucunImage.bottom, kuCunList.frame.size.width-20, 30)];
    nextTitle.text = @"下线订单";
    nextTitle.textColor = DaoHangColor;
    nextTitle.font = [UIFont fontWithName:nil size:15];
    [nextList addSubview:nextTitle];
    
    UITapGestureRecognizer* singleRecognizer;
    singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap)];
    //点击的次数
    singleRecognizer.numberOfTapsRequired = 1; // 单击
    
    // 自动补货订单view
    UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(20, nextList.bottom +25, SCREEN_WIDTH-40, 90)];
    aView.backgroundColor = LineColor;
    aView.layer.cornerRadius = 20 / 2;
    aView.layer.borderColor = BackColor.CGColor;
    aView.layer.borderWidth = 1.0;
    [aView addGestureRecognizer:singleRecognizer];
    [self.view addSubview:aView];
    
    //图片
    UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(25, 25, 40, 40)];
    myImageView.image = [UIImage imageNamed:@"dingdan13"];
    [aView addSubview:myImageView];
    
    
    UILabel *repairCargoList = [[UILabel alloc] initWithFrame:CGRectMake(myImageView.right+15, 10, 100, 30)];
    repairCargoList.text = @"自动补货订单";
    repairCargoList.textColor = DaoHangColor;
    repairCargoList.font = [UIFont fontWithName:nil size:15];
    [aView addSubview:repairCargoList];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(myImageView.right+15, repairCargoList.bottom+0, aView.frame.size.width-myImageView.right-15-25, aView.frame.size.height-(30+30))];
    title.text = @"由线下进货款自动生成，只会给您带来盈利，不会给你造成损失";
    title.numberOfLines = 2;
    title.font = [UIFont fontWithName:nil size:11];
    [aView addSubview:title];
    
    //补货订单说明
    UIButton * addCargoList = [[UIButton alloc] initWithFrame:CGRectMake(aView.center.x-10, aView.bottom, aView.frame.size.width / 2.0+20, 30)];
    [addCargoList setTitle:@"“关于自动补货订单”说明" forState:UIControlStateNormal];
    [addCargoList setTitleColor:[UIColor colorWithRed:93/255.0 green:156/255.0 blue:221/255.0 alpha:1] forState:UIControlStateNormal];
    addCargoList.titleLabel.font = [UIFont fontWithName:nil size:12];
    [addCargoList addTarget:self action:@selector(clickZiDong) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addCargoList];
    
    UIView *nextBackView = [[UIView alloc] initWithFrame:CGRectMake(0, addCargoList.bottom+30, SCREEN_WIDTH, SCREEN_HEIGHT - addCargoList.bottom+30)];
    nextBackView.backgroundColor = LineColor;
    [self.view addSubview:nextBackView];
    
}



#pragma -mark 创建提示框
- (void)createAlertView{
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    _alertBackview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _alertBackview.backgroundColor = [UIColor blackColor];
    _alertBackview.alpha = 0.4;
    [window addSubview:_alertBackview];
    _alerView = [[[NSBundle mainBundle] loadNibNamed:@"Shopping_mall_xibs" owner:self options:nil] objectAtIndex:10];
    _alerView.frame = CGRectMake(50, SCREEN_HEIGHT/2.0-130/2.0, SCREEN_WIDTH-100, 130);
    [_alerView.confirmBut addTarget:self action:@selector(confirmButClick) forControlEvents:UIControlEventTouchUpInside];
    [_alerView.cancelBut addTarget:self action:@selector(cancelButClick) forControlEvents:UIControlEventTouchUpInside];
    [window addSubview:_alerView];
}

#pragma -mark 点击确定
- (void)confirmButClick{
    [_alertBackview removeFromSuperview];
    [_alerView removeFromSuperview];
    
    AccountViewController *offline = [[AccountViewController alloc]init];//绑定状态
    offline.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:offline animated:YES];
}

#pragma -mark 点击提示框稍后按钮
- (void)cancelButClick{
    [_alertBackview removeFromSuperview];
    [_alerView removeFromSuperview];
    
}

#pragma mark - 关于自动补货订单说明
-(void)clickZiDong{
    AutomaticViewController *automatic = [[AutomaticViewController alloc]init];
    [self.navigationController pushViewController:automatic animated:YES];
}
#pragma -mark 点击信封按钮事件
- (void)informationClick{
    
    InfoViewController *infomation =[[InfoViewController alloc] init];
    [self.navigationController pushViewController:infomation animated:YES];
}
#pragma -mark 点击自动补货订单
- (void)singleTap{

    //判断是否交保证金
//    NSString *isPayOffDeposit = [[NSUserDefaults standardUserDefaults] objectForKey:@"IsPayOffDeposit"];
//    if ([isPayOffDeposit isEqualToString:@"0"]) {
//        [self createAlertView];
//        return;
//    }
    self.hidesBottomBarWhenPushed = YES;
    AddCargoListViewController *nextList = [[AddCargoListViewController alloc] init];
    nextList.listVC = self;
    [self.navigationController pushViewController:nextList animated:YES];
}
                        
#pragma -mark 点击下线订单
- (void)nextListClick{
    //判断是否交保证金
//    NSString *isPayOffDeposit = [[NSUserDefaults standardUserDefaults] objectForKey:@"IsPayOffDeposit"];
//    if ([isPayOffDeposit isEqualToString:@"0"]) {
//        [self createAlertView];
//        return;
//    }
    self.hidesBottomBarWhenPushed = YES;
    NextListsController *nextList = [[NextListsController alloc] init];
    nextList.listVC = self;
    [self.navigationController pushViewController:nextList animated:YES];
}

#pragma -mark 点击库存订单
- (void)kuCunListBut:(UIButton *)sender{
    //判断是否交保证金
//    NSString *isPayOffDeposit = [[NSUserDefaults standardUserDefaults] objectForKey:@"IsPayOffDeposit"];
//    if ([isPayOffDeposit isEqualToString:@"0"]) {
//        [self createAlertView];
//        return;
//    }
    self.hidesBottomBarWhenPushed = YES;
     MyListViewController *offlineCv = [[MyListViewController alloc] init];
    offlineCv.listVC = self;
    [self.navigationController pushViewController:offlineCv animated:YES];
}

#pragma -mark 点击客户订单
- (void)keFuListBut:(UIButton *)sender{
    //判断是否交保证金
//    NSString *isPayOffDeposit = [[NSUserDefaults standardUserDefaults] objectForKey:@"IsPayOffDeposit"];
//    if ([isPayOffDeposit isEqualToString:@"0"]) {
//        [self createAlertView];
//        return;
//    }
    self.hidesBottomBarWhenPushed = YES;
     UserListViewController *userlist = [[UserListViewController alloc] init];
     userlist.listVC = self;
    [self.navigationController pushViewController:userlist animated:YES];
    
}
@end
